import request from '@/sheep/request';

interface CartItem {
  // 定义购物车商品数据类型
  // 根据实际情况添加属性
}

interface UpdateCartCountData {
  // 定义更新购物车数量的请求数据类型
  // 根据实际情况添加属性
}

interface UpdateCartSelectedData {
  // 定义更新购物车选中状态的请求数据类型
  // 根据实际情况添加属性
}

const CartApi = {
  addCart: (data: CartItem): Promise<any> => {
    return request({
      url: '/trade/cart/add',
      method: 'POST',
      data: data,
      custom: {
        showSuccess: true,
        successMsg: '已添加到购物车~',
      }
    });
  },
  updateCartCount: (data: UpdateCartCountData): Promise<any> => {
    return request({
      url: '/trade/cart/update-count',
      method: 'PUT',
      data: data
    });
  },
  updateCartSelected: (data: UpdateCartSelectedData): Promise<any> => {
    return request({
      url: '/trade/cart/update-selected',
      method: 'PUT',
      data: data
    });
  },
  deleteCart: (ids: number[]): Promise<any> => {
    return request({
      url: '/trade/cart/delete',
      method: 'DELETE',
      params: {
        ids
      }
    });
  },
  getCartList: (): Promise<any> => {
    return request({
      url: '/trade/cart/list',
      method: 'GET',
      custom: {
        showLoading: false,
        auth: true,
      },
    });
  },
};

export default CartApi;
